var express           = require('express');
var projectAPI    = require('../api/v1/project.js');
var memberAPI    = require('../api/v1/member.js');
var certAPI    = require('../api/v1/cert.js');
var buildConfigAPI    = require('../api/v1/build_cfg.js');
var publishConfigAPI    = require('../api/v1/publish_cfg.js');
var buildAPI    = require('../api/v1/build.js');
var userAPI  = require('../api/v1/user.js');
var workspaceAPI = require('../api/v1/workspace');
var router            = express.Router();
var upload  = require("../common/upload.js");
var local_repoAPI    = require('../api/v1/local_repositories.js');
var productConfigAPI = require('../api/v1/product_cfg.js');
var productAPI = require('../api/v1/product.js');
var publishAPI = require('../api/v1/publish/publish.js');
var dataSourceAPI = require('../api/v1/data_source.js');
var messageAgent = require('../common/message.js');

router.get('/product_config/:_id',productConfigAPI.get);
router.post('/product_configs',productConfigAPI.post);
router.get('/product_configs',productConfigAPI.getList);
router.delete('/product_configs',productConfigAPI.deleteList);
router.delete('/product_configs/:_id',productConfigAPI.delete);
router.put('/product_configs/:_id',productConfigAPI.put);


router.post('/products',productAPI.post);
router.get('/products',productAPI.getList);
router.delete('/products',productAPI.deleteList);
router.delete('/products/:_id',productAPI.delete);
router.put('/products/:_id',productAPI.put);

router.get('/data_source/:_id',dataSourceAPI.get);
router.post('/data_sources',dataSourceAPI.post);
router.get('/data_sources',dataSourceAPI.getList);
router.delete('/data_sources',dataSourceAPI.deleteList);
router.delete('/data_sources/:_id',dataSourceAPI.delete);
router.put('/data_sources/:_id',dataSourceAPI.put);

//router.get('/project/:name', projectAPI.getByName);
router.get('/user',userAPI.getCurrent);
router.get('/user/search',userAPI.getUsers);
router.get('/order_list/:user_name',userAPI.getDepenList);

router.get('/project/:project_id', projectAPI.getById);
router.get('/projects', projectAPI.getList);
router.get('/project', projectAPI.getCurrentProject);
router.post('/project', projectAPI.addProject);
router.patch('/project/:project_id', projectAPI.updateProject);
router.put('/project/pushCert',projectAPI.pushCert);
router.delete('/project/removeCert',projectAPI.removeCert);
router.get('/all_projects',projectAPI.getAllProjects);
router.delete('/project/:project_id',projectAPI.deleteProject);
//router.get('/testproject',projectAPI.testQuery);


router.post('/member', memberAPI.addMember);
router.get('/member/:project_id', memberAPI.getMembers);
router.post('/members', memberAPI.getMembersByshoutids);
router.delete('/member', memberAPI.removeMember);
router.put('/member', memberAPI.updateMember);


router.post('/cert/:project_id',certAPI.addCert);
router.delete('/cert/:cert_id',certAPI.removeCert);
router.get('/cert/:cert_id',certAPI.getCert);
router.put('/cert/:cert_id',certAPI.updateCert);
router.get('/certs/:project_id',certAPI.getCerts);

router.post('/dependency/:project_id',projectAPI.addDependency);
router.delete('/dependency/:project_id',projectAPI.removeDependency);
router.put('/dependency/:project_id',projectAPI.updateDependency);
router.put('/dependencies/:project_id',projectAPI.updateDependencies);

router.get('/workspace/:workspace_id',workspaceAPI.getWorkspaceById);
router.post('/workspace/add',workspaceAPI.addWorkspace);
router.post('/workspace/member/:workspace_id',workspaceAPI.addWkpMember);
router.put('/workspace/member/:workspace_id',workspaceAPI.editWkpMember);
router.delete('/workspace/member/:workspace_id',workspaceAPI.removeWkpMember);
router.get('/workspace/list/:project_id',workspaceAPI.getWorkspaces);
router.post('/workspace/delete',workspaceAPI.deleteWorkspace);
//router.get('/workspace/projects/:wkp_name',workspaceAPI.getAllProjectsInWkp);
router.get('/workspace/projects/:project_id',workspaceAPI.getAllProjectsInWkp);

router.get('/workspace/dependencies/:work_id',workspaceAPI.getDependencies);
router.post('/workspace/dependencies/update',workspaceAPI.updateTarget);
//router.post('/workspace/dependencies/target',workspaceAPI.downloadTarget);
//router.post('/workspace/dependencies/updateTarget',workspaceAPI.updateWorkTargetByProject);

//router.get('/workspace/workspaces',workspaceAPI.getWorkspacesByUser);
router.get('/workspaces',workspaceAPI.getAllWorkspaces);
router.get('/workspaces/shortid',workspaceAPI.getWorkspacesByShortId);
router.post('/workspace/git/check',workspaceAPI.checkGitUrl);

router.post('/buildConfig',buildConfigAPI.addBuildConfig);
router.delete('/buildConfig/:config_id',buildConfigAPI.deleteBuildConfig);
router.delete('/buildConfigs',buildConfigAPI.deleteBuildConfig);
router.get('/buildConfig/:config_id',buildConfigAPI.getBuildConfig);
router.put('/buildConfig',buildConfigAPI.editBuildConfig);
router.get('/buildConfigs/',buildConfigAPI.getConfigList);

router.post('/builds/', buildConfigAPI.start);
router.get('/builds/', buildAPI.getList);
router.get('/builds/:_id', buildAPI.get);
router.delete('/builds/:_id', buildAPI.delete);

//router.get('/upload',upload.upload);

router.post('/local_repo/download',local_repoAPI.download);
router.put('/local_repo/update',local_repoAPI.update);
router.post('/local_repo/copy',local_repoAPI.copy);
router.get('/local_repo',local_repoAPI.getLocalRepo);
router.get('/local_repo/:file_name',local_repoAPI.getFileInfoByName);


router.post('/publishConfig',publishConfigAPI.addPublishConfig);
router.get('/publishConfigs', publishConfigAPI.getList);
router.get('/publishConfig/:publishConfig_id',publishConfigAPI.getPublishConfig);
router.delete('/publishConfig/:publishConfig_id',publishConfigAPI.deletePublishConfig);
router.put('/publishConfig/:publishConfig_id',publishConfigAPI.editPublishConfig);

router.get('/publishGoodsInfo/:config_id',publishConfigAPI.getGoodsInfo);
router.post('/publish',publishAPI.publish);
router.get('/getPublishRec/:publishConfig_id',publishAPI.getPublishRec);
router.delete('/publishRec/:publish_id',publishAPI.deletePublishRec);

router.get('/message/:task_id',messageAgent.handleMessage);


module.exports = router;
